﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace UCNKompetenceBors.Database
{
    public class dbGeneral
    {
        /// <summary>
        /// Executes a stored procedure, based on the input parameters.
        /// </summary>
        /// <param name="sprocName">Specifies the name of the stored procedure to be executed.</param>
        /// <param name="sprocParameters">Specifies the list of parameters of the stored procedure to be executed.</param>
        /// <returns>Returns a boolean.</returns>
        public static bool ExecuteStoredProc(string sprocName, List<SqlParameter> sprocParameters)
        {
            string connString = ConfigurationManager.ConnectionStrings["ConnStringDB"].ConnectionString;
            using (SqlConnection con = new SqlConnection(connString))
            {
                SqlCommand cmd = new SqlCommand(sprocName, con);
                cmd.CommandType = CommandType.StoredProcedure;

                if (sprocParameters != null)
                {
                    foreach (SqlParameter param in sprocParameters)
                    {
                        cmd.Parameters.Add(param);
                    }
                }

                con.Open();
                return Convert.ToBoolean(cmd.ExecuteScalar());
            }
        }
    }
}